import torch
from torch import nn

net = nn.Sequential(
    nn.Conv2d(1, 6, kernel_size=5, padding=2), nn.Sigmoid(),
    nn.AvgPool2d(kernel_size=2, stride=2),
    nn.Conv2d(6, 16, kernel_size=5), nn.Sigmoid(),
    nn.AvgPool2d(kernel_size=2, stride=2),
    nn.Flatten(),
    nn.Linear(16 * 5 * 5, 120), nn.Sigmoid(),
    nn.Linear(120, 84), nn.Sigmoid(),
    nn.Linear(84, 10))

import torch.utils
import torch.utils.data
import torch.utils.data.dataloader
import torch.utils.data.dataset
import numpy as np

torch.set_default_dtype(torch.float32)

with open("动手学深度学习\data\minst_dataset\mnist_train.csv","r") as f:
    data1 = f.readlines()
    train_data = np.asfarray([d.split(',') for d in data1])
    # train_data = torch.tensor(train_data,dtype=tp)
    train_data = [(x,y) for y,*x in train_data]
    train_iter = torch.utils.data.DataLoader(train_data,batch_size=256)

with open("动手学深度学习\data/minst_dataset/mnist_test.csv","r") as f:
    data1 = f.readlines()
    test_data = np.asfarray([d.split(',') for d in data1])
    # test_data = torch.Tensor(test_data,dtype=tp)
    test_data = [(x,y) for y,*x in test_data]

    test_iter = torch.utils.data.DataLoader(test_data,batch_size=256)

print(next(iter(test_iter)))